<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>高拍仪Demo</title>
</head>
<body onload ="InitCamOCX();" onunload = "UnInitCamOCX();">	

<!-- border="1" -->
<table  width="100%" height="100%">
<tr width="100%" height="100%">
<!--左列-->
<td width="40%" height="100%">
	<table width="100%" height="60%">
		<tr height="20" >
		</tr>
         <tr >
		     <td colspan="5" height="100%">
			      <OBJECT id="CamSDKOCX" width="100%" height="100%" classid="clsid:556DBC8A-FE4A-4DA7-A82E-3926C8D4AC41" >
					</OBJECT>
			 </td>
		 </tr>
	</table>
	<table width="100%" height="30%">
	
		 <tr height="40">
		     <td width="100">预览缩放：</td>
		     <td colspan="4">
			 <input type = "button" value = "+" onClick="ZoomIN()" style = "margin-left:5; width:20%; text-align:center";>
		     <input type = "button" value = "-" onClick="Zoomout()" style = "margin-left:5; width:20%; text-align:center">
		     <input type = "button" value = "1:1" onClick="OriginalPreview()" style = "margin-left:5; width:20%; text-align:center">
		     <input type = "button" value = "best" onClick="OptimalPreview()" style = "margin-left:5; width:20%; text-align:center">
			 </td>
		 </tr>
		 <tr height="40">
			<td colspan="5">设备控制/参数设置：</td>
		 </tr>
		 <tr height="40">
			<td colspan="3" width="60%">
			设备：
			<select name="DeviceList" id = "DeviceList" onchange = "ChangeDevice()" style = " width:60%"></select></td>
			<td colspan="2" width = "40%">
			<input type = "button" value = "设备设置" onClick="ShowDevSettingWindow()" style = "width:80; text-align:center">
			<input type = "button" value = "图像设置" onClick="ShowImageSettingWindow()" style = "margin-left:5; width:80; text-align:center">
			</td>
		 </tr>
		 <tr height="40">
		 	<td width="40%" colspan="2">
			视频格式:
			<select name="MediaType" id = "MediaType" onchange = "SetMediaType(MediaType)" style = "width:60%"></select></td>
			<td width="60%" colspan="3">
			分辨率：
			<select name="Resolution" id = "Resolution" onchange = "SetResolution(Resolution)" style = "width:60%"></select></td>
		 </tr height="50">
		 <tr height="40">
			<td colspan="5">
			<input type = "button" value = "蜂鸣" onClick="EnableBuzzer()" style = "width:80; text-align:center">
			<input type = "button" value = "一键对焦" onClick="AutoFocus()" style = "width:80; text-align:center">
			</td>
		 </tr>
	</table>
	<table width="100%" height="10%">
	</table>
</td>
<!--右列-->
<td width="40%" height="100%">
	<table  width="100%" height="10%" >
		<tr height="20">
		</tr>
		<tr height="40">
			<td width="80">
				存储路径：
			</td>
			<td>
				<input style="width:100%" type = "text" name="path" id="path" value="C:\temp" onchange="SetSaveFolder()" >
			</td>
			<td>
				<a id="saveFolder" style = "width:60;" href="C:\temp">openFolder</a>
			</td>
			<td width="125">
			<!--
			<input type = "button" value = "浏览" onClick="browseFolder('path')" style = "width:60; text-align:center">			
			<input type = "button" value = "打开" onClick="()" style = "width:60; text-align:center">
				-->
			</td>

		</tr>
	</table>
	<table width="100%" height="60%">
		<tr height="40">
			<td colspan="6">
			 拍照（图像处理）：
			</td>
		</tr>
		<tr height="40">
			
			<td>颜色类型：
				<select style = "width:90;" name = "colorstyle" id = "colorstyle" onchange = "SetColorStyle(colorstyle)">
					<option value="0">彩色</option>
					<option value="1">灰度</option>
					<option value="2">黑白</option>
				</select>
			</td>
			<td>PS 特 效: 
				&nbsp&nbsp
				<select style = "width:90;" name = "PS" id = "PS" onchange = "SetAdjust(PS)">
					<option value="0">无效果</option>
					<option value="1">文档增强</option>
					<option value="2">色彩增强</option>
					<option value="4">灰色(Gray)</option>
					<option value="5">黑白(Black & White)</option>
					<option value="6">油画(Painterly)</option>
					<option value="7">怀旧(Nostalgic)</option>
					<option value="8">素描(Sketch)</option>
					<option value="9">边缘照亮(Glowing Edge)</option>
					<option value="10">蓝冷(Cold Blue)</option>
					<option value="11">马赛克(Mosaic)</option>
					<option value="12">模糊(Blurry)</option>
					<option value="13">负片(Negative)</option>
				</select>			
			</td>
			<td></td>
		</tr>
		<tr height="40">
				<td>图像类型：
					<select style = "width:90;" name = "filetype" id = "filetype" onchange = "">
						<option value=".jpg">jpg</option>
						<option value=".bmp">bmp</option>
						<option value=".png">png</option>
						<option value=".tif">tif</option>
						<option value=".ico">ico</option>
						<option value=".pdf">pdf</option>
					</select>
				</td>
				<td>JPG 质量：
				<input type = "text" style="width:90;" name = "JPGQ" id = "JPGQ"  value = " 75" onchange = "SetJPGQuanlity(JPGQ)"/>
				</td>
				<td></td>
		</tr>
		<tr height="40">
				<td>裁切类型：
					<select style="width:90;" name="autocrop" id="autocrop" onchange = "SetAutoCrop(autocrop)">
						<option value="0">不裁切</option>
						<option value="1">单图裁切</option>
						<option value="2">多图裁切</option>
						<option value="3">单图裁切 & 补边</option>
						<option value="4">书本</option>
					</select>
				</td>
				<td>旋转类型：
					<select style = "width:90;" name = "rotate" id = "rotate" onchange = "SetRotateState(rotate)">
						<option value="0">0度</option>
						<option value="1">90度</option>
						<option value="2">180度</option>
						<option value="3">270度</option>
					</select>
				</td>
				<td></td>
		</tr>
			<td colspan="4">
				PS: 手动裁切有两个接口可开启。其中一个可设置区域位置，有效值范围1~100。如左上设置为10，左顶的坐标即为 x=视频宽*10%，y=视频高*10%
			</td>
		</tr>
		<tr rowspan="2" height="40">
				<td width="80">
				<input type = "checkbox" name = "CurCrop" id = "CurCrop" onClick="SetCusCrop(CurCrop)"/>
				手动裁切
				</td>
				<td colspan="3">
				左：<input style = "width:40;" type = "text" name = "leftValue" id = "leftValue"  value = " 10" />
				上：<input style = "width:40;" type = "text" name = "topValue" id = "topValue"  value = " 10" />
				右：<input style = "width:40;" type = "text" name = "rightValue" id = "rightValue"  value = " 90" />
				下：<input style = "width:40;" type = "text" name = "bottomValue" id = "bottomValue"  value = " 90" />
				&nbsp&nbsp<input type = "button" value = "设置手裁框" onClick="SetImageCusCropRect()" style = "width:100; text-align:center">
				</td>
		</tr>
		<tr height="40">
				<td colspan="4" width="80">DPI: 
					&nbsp&nbsp&nbsp&nbsp
					X:<input style = "width:40;" type = "text" name = "xdpi" id = "xdpi"  value = "0" onchange = "SetImageDPI()"/>
					&nbsp&nbsp&nbsp&nbsp
					Y:<input style = "width:40;" type = "text" name = "ydpi" id = "ydpi"  value = "0" onchange = "SetImageDPI()"/>
				</td>
		</tr>
		<tr rowspan="2" height="40">
				<td>
				<input type = "checkbox" name = "Denoise" id = "Denoise" onClick="SetDenoise(Denoise)"/>
				去噪
				</td>
				<td>								
				<input type = "checkbox" name = "ImageFileSign" id = "ImageFileSign" onClick="SetImageFileSign(ImageFileSign)"/>
				防篡改
				</td>				
		</tr>
		<tr>
			<td colspan="4">
				<input type = "button" value = "图片验证" style = "margin-left:5px"  onclick = "CheckImageFileSign()">
				<input type = "file" name="CheckFile" id="CheckFile" value="选取文件">
			</td>
		</tr>
		<tr colspan="2">
			<td>
				<input type = "button" value = "拍照" onClick="Capture()" style = "width:60; text-align:center">
				<input type = "button" value = "拍照（显示）" onClick="CaptureShow()" style = "width:100; text-align:center">
			</td>
			<td width=120> 
				<input type = "button" value = "拍照（base64）" onClick="CaptureBase64()" style = "width:120; text-align:center">
			</td>
			<td>
				<img ID="imgPreview" src="" border="1" width="100" height="100"/> 
			</td>
		</tr>
		<tr>
			<td colspan="4">
				<input type = "button" value = "自动连拍" onClick="AutoCapture(0)" style = "width:80; text-align:center">
				<input type = "button" value = "定时连拍" onClick="AutoCapture(1)" style = "width:80; text-align:center">
			</td>
		</tr>
	</table>
	<table  width="100%" height="30%">
		<tr height="40">
			<td colspan="2" >
				录像：
			</td>
		</tr>
		<tr height="40">
			<td width = "50%">
			麦克风：
			<select name="AudioList" id = "AudioList" onchange = "()" style = " width:60%"></select>
			</td>
			<td>
			录像格式：
			<select name="RecordType" id = "RecordType" onchange = "()" style = " width:60%">
				<option value=".avi">avi</option>
				<option value=".mp4">mp4</option>
				<option value=".flv">flv</option>
			</select>
			</td>
		</tr>
		<tr height="40">
			<td colspan="2">
			音量：
			<input style = "width:180;" type = "text" name = "volume" id = "volume"  value = "录像时当前音量"/>
			</td>
		</tr>
		<tr height="40">
			<td colspan="2">
			<input type = "button" value = "开始录像" onClick="StartRecord()" style = "width:80; text-align:center">
			<input type = "button" value = "停止录像" onClick="StopRecord()" style = "width:80; text-align:center">
			</td>
		</tr>
		<tr>
</tr>
	</table>
</td>
</tr>
</table>
</body>
</html>

<script>
function InitCamOCX()
{
	var ret = CamSDKOCX.InitCameraLib();
	if(ret)
	{
		if(ret == 263)
		{
			alert("ocx初始化成功，但是没有授权");
		}
		else
		{
			alert("OCX初始化失败，错误号：" + ret);
			return;
		}
	}
	//开启0号摄像头
	//StartVideo();
	setTimeout("StartVideo()",200);
}
<!--反初始化-->
function UnInitCamOCX() 
{
	CamSDKOCX.UnInitCameraLib();
}
<!--清空列表-->
function clean(list)
{
　　while (list.options.length>0)
　　{
　　 list.options.remove(0);
　　}
}
<!--设置目录-->
function SetSaveFolder()
{
	saveFolder.href = path.value;
}
<!--更新设备列表-->
function AddDevice() 
{
	clean(DeviceList);
    var mainDevCount = 0;
    var total = CamSDKOCX.GetDevCount();
	for(var i = 0 ; i < total ; i++ )
	{
	    var devtype = CamSDKOCX.GetDevType(i);
	    //if (devtype == 0) {//0 主头
	        var DevEle = CamSDKOCX.GetDevName(i);
			DeviceList.options.add(new Option(DevEle,i));
	        //DeviceList.options[mainDevCount].text = DevEle;
	        mainDevCount++;       
        //}	
	}
	if(mainDevCount > 0)
	{
		mainIndex = 0;
		DeviceList.options[0].selected = true;
	}
	
}
<!--更新媒体类型列表-->
function AddMediaType(list)
{
	clean(list);
	total = CamSDKOCX.GetMediaTypeCount();
	for(var j = 0 ; j < total ; j++ )
	{   
		var mediatypeName = CamSDKOCX.GetMediaTypeName(j);
		list.options.add(new Option(mediatypeName));
		//list.options[j].text=mediatypeName ;
    }
    list.options[0].selected = true;
}
<!--设置媒体类型-->
function SetMediaType(MediaType)
{
	//var obj=document.getElementById("MediaType") ;
	var index=MediaType.selectedIndex;
	CamSDKOCX.SetMediaType(index);
}
<!--更新分辨率列表-->
function AddResolution2Comb(list)
{
	clean(list);
	var total = CamSDKOCX.GetResolutionCount();
	for(var i = 0 ; i < total ; i++ )
	{   
		var width = CamSDKOCX.GetResolutionWidth(i);
		var height = CamSDKOCX.GetResolutionHeight(i); 
		var resolution = width+" x "+height;
		list.options.add(new Option(resolution));
		//list.options[i].text=resolution;
    }
    list.options[0].selected = true;
}

<!--设置分辨率-->
function SetResolution(Resolution)
{   
	//var obj=document.getElementById("Resolution") ;
	var index=Resolution.selectedIndex;
	var width = CamSDKOCX.GetResolutionWidth(index);
	var height = CamSDKOCX.GetResolutionHeight(index); 
	CamSDKOCX.SetResolution(width,height);
}

<!--预览缩放-->

function ZoomIN()
{
	CamSDKOCX.ZoomIn();
}
function Zoomout()
{
	CamSDKOCX.Zoomout();
}
function OriginalPreview()
{
	CamSDKOCX.OriginalPreview();
}
function OptimalPreview()
{
	CamSDKOCX.OptimalPreview();
}

<!--切换摄像头-->
function ChangeDevice()
{	
	CamSDKOCX.CloseDev();
	var obj = document.getElementById("DeviceList") ;
	var index = obj.selectedIndex;
	if(index >= 0)
	{
		CamSDKOCX.openDev(index,0,0,0);	
		AddMediaType(MediaType);
		AddResolution2Comb(Resolution);
	}
}
<!-- 打开UVC驱动设置窗口 -->
function ShowDevSettingWindow()
{
	CamSDKOCX.ShowDevSettingWindow();
}
function ShowImageSettingWindow()
{
	CamSDKOCX.ShowImageSettingWindow();
}
<!--蜂鸣-->
function EnableBuzzer()
{
	//鸣响两声，每次响300毫秒，间隔500毫秒
	CamSDKOCX.EnableBuzzer(2,300,500);
}
function AutoFocus()
{
	//一键对焦
	CamSDKOCX.AutoFocus(0);
}
<!--图片色彩-->
function SetColorStyle(obj)
{
	var type = obj.selectedIndex;
	CamSDKOCX.SetColorStyle(type);
}
<!--图片效果-->
function SetAdjust(obj)
{
	var type = obj.selectedIndex;
	CamSDKOCX.SetAdjust(type);
}
//<!--图片扩展名-->
//function SetAdjust(obj);
//{
//	var type = obj.selectedIndex;
//	CamSDKOCX.SetAdjust(type);
//}
<!--图片质量-->
function SetJPGQuanlity(obj)
{
	CamSDKOCX.SetJPGQuanlity(obj.value);
}
<!--裁切类型-->
function SetAutoCrop(obj)
{
	//var obj=document.getElementById("autocrop") ;
	var index = obj.selectedIndex;
	CamSDKOCX.SetAutoCrop(index);
}
<!--旋转效果-->
function SetRotateState(obj)
{
	var index=obj.selectedIndex;
	CamSDKOCX.SetImageRotateMode(index);
}
<!--手动裁切-->
function SetCusCrop(obj)
{
	if(obj.checked)
	{
		CamSDKOCX.SetCusCrop(1);
	}
	else
	{
		CamSDKOCX.SetCusCrop(0);
	}
}
<!--设置手动裁切区域-->
function SetImageCusCropRect()
{
	//参数是坐标百分比
	CamSDKOCX.SetImageCusCropRect(leftValue.value,topValue.value,rightValue.value,rightValue.value);
}
<!--设置DPI-->
function SetImageDPI()
{
	CamSDKOCX.SetImageDPI(xdpi.value, ydpi.value);
}
<!--去噪-->
function SetDenoise(obj)
{
	if(obj.checked)
	{
		CamSDKOCX.SetDenoise(1);
	}
	else
	{
		CamSDKOCX.SetDenoise(0);
	}
	
}
<!--防篡改-->
function SetImageFileSign(obj)
{
	if(obj.checked)
	{	
		CamSDKOCX.SetImageFileSign(1);
	}	
	else
	{
		CamSDKOCX.SetImageFileSign(0);
	}
}
function CheckImageFileSign()
{
	if(CamSDKOCX.CheckImageFileSign(document.getElementById("CheckFile").value) == 1)
	{
		alert("加入防篡改文件");
	}
	else
	{
		alert("文件未标记，或者已经修改");
	}
}
 
/*
myDate.getYear(); //获取当前年份(2位)
myDate.getFullYear(); //获取完整的年份(4位,1970-????)
myDate.getMonth(); //获取当前月份(0-11,0代表1月)
myDate.getDate(); //获取当前日(1-31)
myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
myDate.getHours(); //获取当前小时数(0-23)
myDate.getMinutes(); //获取当前分钟数(0-59)
myDate.getSeconds(); //获取当前秒数(0-59)
myDate.getMilliseconds(); //获取当前毫秒数(0-999)
myDate.toLocaleDateString(); //获取当前日期
var mytime=myDate.toLocaleTimeString(); //获取当前时间
myDate.toLocaleString(); //获取日期与时间
*/
<!--拍照-->
function Capture()
{
	var fileext = document.getElementById("filetype").value;
	var strFolder = document.getElementById("path").value;
	var myDate = new Date();
	var myName = "Image_"+myDate.getFullYear()+(myDate.getMonth()+1)+myDate.getDate()+"_"+myDate.getHours()+myDate.getMinutes()+myDate.getSeconds()+myDate.getMilliseconds();
	//myDate.getTime()
	var newFile = strFolder + "\\" + myName + fileext ;
	var files = CamSDKOCX.CaptureImage(newFile);
	//alert(newFile);
	return newFile;
}
<!--拍照（显示）-->
function CaptureShow(obj)
{
	var files = Capture();
	var strs= new Array(); //定义一数组 
	strs=files.split(";"); //字符分割 
	for (i=0;i<strs.length ;i++ ) 
	{ 
		CamSDKOCX.ShowImage(strs[i]);
	} 

}
<!--拍照（base64）-->

function showImageBase64(strBase64)
{
   document.getElementById("imgPreview").src = "data:image/jpeg;base64,"+strBase64;
   	
}
function CaptureBase64(obj)
{
	var files = Capture();
	var strs= new Array(); //定义一数组 
	strs=files.split(";"); //字符分割 
	for (i=0;i<strs.length ;i++ ) 
	{ 
		var strBase64 = CamSDKOCX.EncodeBase64(strs[i]);
		//alert(strBase64);
		//显示到窗口
		showImageBase64(strBase64);	
	} 
}
<!--连拍-->
function AutoCapture(mode)
{
	var ret = CamSDKOCX.StartAutoCapture(path.value,mode,5);
	if(ret)
	{
		alert("连拍启动失败，错误码："+ret);
	}
}
<!--麦克风-->
function AddAudioDev(obj)
{
	var nCount = CamSDKOCX.GetAudioDevCount();
	for(var i = 0 ; i < nCount ; i++ )
	{
	    var DevEle = CamSDKOCX.GetAudioDevName(i);
		obj.options.add(new Option(DevEle));
	}
	if(nCount > 0)
	{
		obj.options[0].selected = true;
	}
}
//<!--录像格式-->
//function ();
//{
//}

var dom = 0;
//dom = window.setInterval(GetMicrophoneVolumeLevel(),5);
<!--音量-->
function GetMicrophoneVolumeLevel()
{
    //alert("1");
	volume.value = CamSDKOCX.GetMicrophoneVolumeLevel();
}
<!--开始录像-->
function StartRecord(obj)
{
	var fileext = document.getElementById("RecordType").value;
	var strFolder = document.getElementById("path").value;
	var myDate = new Date();
	var myName = "video_"+myDate.getFullYear()+(myDate.getMonth()+1)+myDate.getDate()+"_"+myDate.getHours()+myDate.getMinutes()+myDate.getSeconds()+myDate.getMilliseconds();
	
	var newFile = strFolder + "\\" + myName + fileext ;
	//新SDK,videoFormat暂无意义
	var ret = CamSDKOCX.StartRecord(newFile,AudioList.selectedIndex,0);
	if(ret)
	{
		alert("开始录像失败，错误号:" + ret);
		return;
	}
	dom = window.setInterval(GetMicrophoneVolumeLevel, 1000); 
}
<!--停止录像-->
function StopRecord()
{
	CamSDKOCX.StopRecord();
	window.clearInterval(dom); 
	volume.value = 0;
}

<!-- 选择目录 -->
function browseFolder(path) {
    try {
        var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息
        var Shell = new ActiveXObject("Shell.Application");
        //var Folder = Shell.BrowseForFolder(0, Message, 64, 17); //起始目录为：我的电脑
        var Folder = Shell.BrowseForFolder(0, Message, 0); //起始目录为：桌面
        if (Folder != null) {
            Folder = Folder.items(); // 返回 FolderItems 对象
            Folder = Folder.item(); // 返回 Folderitem 对象
            Folder = Folder.Path; // 返回路径
            if (Folder.charAt(Folder.length - 1) != "\\") {
                Folder = Folder + "\\";
            }
            document.getElementById(path).value = Folder;
            return Folder;
        }
    }
    catch (e) {
        alert(e.message);
    }
}

<!-- 打开摄像头 -->
function StartVideo() {
	AddDevice();
	//打开列表所选摄像头
	ChangeDevice();
	AddAudioDev(AudioList);
}
</script>
<SCRIPT>
//setTimeout("StartVideo()",100);
</SCRIPT>